<template>
	<view class="">
		<uni-nav-bar dark :fixed="true" shadow background-color="#fff" status-bar left-icon="left" :title="showTitle"  color="#333" @clickLeft="back" />
	
		<view class="pinggu_view">

			<view class="pging_sy" v-if="isDoing">
				<image src="../../static/doing.png" class="doing_img"></image>
				<view class="do_text">
					正在加紧模拟评估，请稍等！
				</view>
			</view>
			<view v-if="!isDoing">
				
			
			<view class="search_boxs_sy" :style="{'top':($store.state.jiaonang.bottom+4)+'px'}">
				<view class="search_box">
					<uni-search-bar  radius="50" placeholder="输入学校名称查询" clearButton="auto" cancelButton="none" v-model="searchValue" class="search_input"/>
					<view class="c_btn" @click="searchQuery">
						搜索
					</view>
				</view>
				<view class="shaixuan2">
					<view class="pt1">
						学校列表（{{dataList.length}}所）
					</view>
					<view class="pt2" @click="searchHandle('type')">
						<!-- <span class="c_text">学校类型</span><span class="c_sanj" :class="showType == 1?'active':''"></span> -->
						<span  class="c_text">{{schoolTypeSel == -1 ? '学校类型':(schoolType[schoolTypeSel] && schoolType[schoolTypeSel].name)}}</span> <span class="c_sanj" :class="showType == 1?'active':''"></span>
					</view>
					<view class="pt2" @click="searchHandle('xuequ')">
						<!-- <span  class="c_text">所属学区</span> <span class="c_sanj" :class="showType == 2?'active':''"></span> -->
						<span  class="c_text">{{schoolListSel == -1 ? '所属学区':(schoolList[schoolListSel] && schoolList[schoolListSel].name)}}</span> <span class="c_sanj" :class="showType == 2?'active':''"></span>
					</view>
				</view>
				<view class="c_xuanxiang" v-if="isShowSc2">
					<template v-if="showType == 1">
						
						<view class="c_xuanxiang_neirong">
							<view class="c_item_xx" @click="changeSearch(-1,'type')">
								全部
							</view>
							<view class="c_item_xx" v-for="(item,key) in schoolType" @click="changeSearch(key,'type')">
								{{item.name}}
							</view>
						</view>
					</template>
					<template v-if="showType == 2">
						<view class="c_xuanxiang_neirong">
							<view class="c_item_xx" @click="changeSearch(-1,'area')">
								全部
							</view>
							<view class="c_item_xx" v-for="(item,key) in schoolList" @click="changeSearch(key,'area')">
								{{item.name}}
							</view>
						</view>
					
					</template>
				</view>
			</view>
			<view class="sc_list" v-if="dataList.length > 0">
				<view class="sc_item_view">
					<sy-school1 :cItem="cItem" v-for="cItem in dataList" @showDetail="toDetail"></sy-school1>
				</view>
			</view>
			<view class="pging_sy" v-if="dataList.length == 0">
				<image src="../../static/nopage.png" class="doing_img"></image>
				<view class="do_text">
					暂无符合的学校！
				</view>
			</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isDoing:true,
				searchValue:"",
				schoolList:[],
				schoolListSel:-1,
				schoolType:[],
				schoolTypeSel:-1,
				isShowSc2:false,
				showType:0,
				dataList:[],
				page:1,
				orderId:"",
				showTitle:"获取评估",
				propPage:"",
				eid:""
			};
		},
		onLoad(ph) {
			let pages = getCurrentPages(); // 获取当前页面栈
			if (pages.length > 1) {
			    let prevPageRoute = pages[pages.length - 2].route; // 获取上一个页面的路由信息
			    console.log(prevPageRoute); // 输出上一个页面的路由信息
				this.propPage = prevPageRoute
			} else {
			    console.log("没有上一个页面");
			}
			if(ph.orderId){
				this.orderId = ph.orderId
			}
			this.getSchoolTyle();
			this.getData();
		},
		mounted() {
			setTimeout(()=>{
				this.isDoing = false;
				// uni.setNavigationBarTitle({
				// 	title:"志愿评估结果"
				// })
				this.showTitle = "志愿评估结果"
			},1000)
		},
		onReachBottom(){
		    let that = this
		    //每次上拉加载的数据比上一次多十个
			if(this.isCanUp){
				++this.page;
				setTimeout(()=>{
					that.getData()
				},200)
			}
		},
		methods:{
			toDetail(cItem){
				console.log(cItem)
				uni.navigateTo({
					url:"/pages/school/schoolDetailSmall?id="+cItem.id+"&eid"+this.eid
				})
			},
			back(){
				if(this.propPage.indexOf('orderAdmin') > -1){
					uni.navigateBack()
				}else{
					uni.switchTab({
						url:"/pages/mine/mine"
					})
				}
			},
			changeSearch(key,type){
				console.log(key,type,"key,type")
				if(type === 'area'){
					this.schoolListSel = key
				}
				if(type === 'type'){
					this.schoolTypeSel = key
				}
				this.showType = 0;
				this.isShowSc2 = false;
				this.getData();
			},
			getSchoolTyle(){
				this.$queryApi("post","/school.school/type", {}, res => {
					console.log(res,"学区类型")
					this.schoolList = res.data.area;
					this.schoolType = res.data.type;
				},"","noMsg")
			},
			getData(){
				uni.showLoading()
				console.log(this.schoolTypeSel,"this.schoolTypeSel")
				let type = this.schoolTypeSel > -1 ?this.schoolType[this.schoolTypeSel].id:"";
				let area = this.schoolListSel > -1 ?this.schoolList[this.schoolListSel].id:"";
				
				this.$queryApi("post","/school.order/filling", {
					pagesize:10,
					page:this.page,
					type,
					area,
					keyword:this.searchValue,
					id:this.orderId
				}, res => {
					console.log(res,"学校")
					this.eid =  res.data.eid;
					let kongList = res.data.data;
					if(this.page == 1){
						this.dataList =  kongList;
					}else{
						this.dataList =  [...this.dataList,...kongList];
					}
					setTimeout(()=>{
						uni.hideLoading()
					},500)
				},"","noMsg")
			},
			searchQuery() {
				this.page = 1;
				this.getData();
			},
			searchHandle(type){
				
				if(type == 'type'){
					if(this.showType != 1){
						this.showType = 1;
						this.isShowSc2 = true;
					}else{
						this.showType = 0;
						this.isShowSc2 = false;
					}
				}
				if(type == 'xuequ'){
					if(this.showType != 2){
						this.showType = 2;
						this.isShowSc2 = true;
					}else{
						this.showType = 0;
						this.isShowSc2 = false;
					}
				}
			}
		}
	}
</script>

<style lang="scss">
.pinggu_view{
	background-color: #fff;
	min-height: 100vh;
	
	.sc_item_view{
		flex-direction: column;
		padding: 200rpx 30rpx 60rpx;
	}
}
</style>
